#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 250 + 10;
const int MOD = 1e9 + 7;
int t, n, m;
int a[MAXN][MAXN];

ll b[MAXN << 1], c[MAXN << 1];
int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);

    cin >> t;
    while (t--) {
        cin >> n >> m;
        memset(b, 0, sizeof(b));
        memset(c, 0, sizeof(c));
        for (int i=1; i<=n; i++) {
            for(int j=1;j<=m;j++) {
                cin >> a[i][j];
                b[i+j] += a[i][j];
                c[i-j+210] += a[i][j];
            }
        }
        ll res = 0;
        for (int i=1; i<=n; i++) {
            for(int j=1;j<=m;j++) {
                res = max(res, b[i+j]+c[i-j+210]-a[i][j]);
            }
        }
        cout << res << endl;
    }
    return 0;
}